package com.example.canalclientsync.script;

import com.example.canalclientsync.canal.handler.VirtualModelHandler;
import com.example.canalclientsync.canal.mapper.db1.ModelMapper;
import com.example.canalclientsync.canal.po.VirtualModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 模型数据同步
 *
 * @author chen.cr
 * @since 2023/10/17
 */
@Component
@Slf4j
public class VirtualModelSync extends BasicSync<VirtualModel, Long> {

    @Resource
    private ModelMapper modelMapper;
    @Resource
    private VirtualModelHandler virtualModelHandler;


    @Override
    long countTotal() {
        return modelMapper.findAllDataCount();
    }

    @Override
    List<VirtualModel> findPageData(long offset, int limit) {
        return modelMapper.findPageData(offset, limit);
    }

    @Override
    void sync0(VirtualModel virtualModel) {
        // 历史数据有 visible=1 的需要过滤，所以这里用update
        virtualModelHandler.update(null, virtualModel);
    }

    @Override
    Long getKey(VirtualModel virtualModel) {
        return virtualModel.getModelId();
    }

}
